/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.common.util;

import java.util.Collection;

import eu.medsea.mimeutil.MimeUtil;
import eu.medsea.mimeutil.detector.MimeDetector;

/**
 * @author CSJ (email:raulcsj@163.com)
 * @since 2013-3-7
 */
public final class DetectUtil {
    /****************************************
     * 文件头标识符探测
     ****************************************/
    private static final String MAGIC_MIME_DETECTOR = "eu.medsea.mimeutil.detector.MagicMimeMimeDetector";

    static MimeDetector mimeDetector;
    static {
        mimeDetector = MimeUtil.registerMimeDetector(MAGIC_MIME_DETECTOR);
    }

    public static final String getRealType4Byte(byte[] fileBody) {
        if (!MAGIC_MIME_DETECTOR.equals(mimeDetector.getName())) {
            mimeDetector = MimeUtil.registerMimeDetector(MAGIC_MIME_DETECTOR);
        }
        Collection<?> mimeTypes = MimeUtil.getMimeTypes(fileBody);
        return mimeTypes.toString();
    }
}
